View Javadoc
1   /*
2    * Copyright 2004 Diogo Quintela (dquintela@users.sourceforge.net)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.whatsnew.options;
17  
18  import net.sf.whatsnew.exceptions.*;
19  
20  
21  /***
22   * <p>
23   * An Option
24   * </p>
25   *
26   * @author <a href="mailto:dquintela@users.sourceforge.net">Diogo Quintela</a>
27   * @version $Id: Option.java,v 1.1 2004/05/13 01:22:30 dquintela Exp $
28   */
29  abstract class Option {
30      /*** The option default value */
31      private final Object defaultValue;
32  
33      /***
34       * Creates a new Option object.
35       *
36       * @param defaultValue Option default value
37       */
38      protected Option(Object defaultValue) {
39          this.defaultValue = defaultValue;
40      }
41  
42      /***
43       * Getter for {@link #defaultValue}
44       *
45       * @return The property value
46       */
47      public Object getDefaultValue() {
48          return defaultValue;
49      }
50  
51      /***
52       * Gets value
53       *
54       * @param value The value to associate, or <code>null</code> to use default
55       *        value
56       *
57       * @return The option value
58       *
59       * @throws InvalidOptionValue If the object type is invalid
60       */
61      public OptionValue getValue(Object value)
62      throws InvalidOptionValue {
63          Object optionValue = (value != null) ? value : defaultValue;
64          return getOptionValue(optionValue);
65      }
66  
67      /***
68       * Gets option value
69       *
70       * @param value The value to use if possible
71       *
72       * @return The option value
73       *
74       * @throws InvalidOptionValue If the object type is invalid
75       */
76      protected abstract OptionValue getOptionValue(Object value)
77      throws InvalidOptionValue;
78  }
79  // EOF